package com.example.service.impl;

import com.example.domain.Student;
import com.example.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class StudentServiceImpl implements StudentService {

    private static Map<Long,Student> studentMap;

    static {
        studentMap = new HashMap<>();
        studentMap.put(1L,new Student(1L,"张三",24));
        studentMap.put(2L,new Student(2L,"李四",20));
        studentMap.put(3L,new Student(3L,"王五",23));
    }

    @Override
    public List<Student> findAllStudent() {
        return studentMap.values().parallelStream().collect(Collectors.toList());
    }

    @Override
    public Student findStudentById(Long id) {
        return studentMap.get(id);
    }

    @Override
    public Student saveOrUpdateStudent(Student student) {
        return studentMap.put(student.getId(),student);
    }

    @Override
    public Boolean deleteStudentById(Long id) {
        return studentMap.remove(id) != null;
    }
}
